package com.atguigu.yygh.task.config;

import com.atguigu.yygh.rabbitmq.constant.RabbitMQConstant;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author:hx
 * @DateTime:2022/11/21 13:42
 * @Description:
 */
@Configuration
public class TaskConfig {
    @Bean(value = "exchange")
    public Exchange getExchange(){
        return ExchangeBuilder.directExchange(RabbitMQConstant.EXCHANGE_DIRECT_TASK).build();
    }

    @Bean(value = "queue")
    public Queue getQueue(){
        return QueueBuilder.durable(RabbitMQConstant.QUEUE_TASK).build();
    }

    @Bean
    public Binding BindingExchangeQueue(@Qualifier(value = "exchange") Exchange exchange,@Qualifier(value = "queue") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with(RabbitMQConstant.ROUTING_TASK).noargs();
    }
}
